﻿/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 8/3/2009
 * Time: 6:36 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;


namespace TaskManagerGadget
{
	/// <summary>
	/// Description of Start.
	/// </summary>
	public class Start
	{
		public enum optionsType { Demo }
		
		public Start(SidebarContainer sidebarContainer):base(sidebarContainer){
						
			if( !File.Exists(file_config) || !ini_config.isSectionExist("Setting") ){
				ini_config.setValue( "Setting", "Name", "Task Manager gadget" );
				ini_config.setValue( "Setting", "Description", "List and view your tasks" );
			}
									
			if( !ini_config.isKeyExist( "Setting", "Options" ) ){
				Hashtable options = new Hashtable();
				//options.Add( optionsType.Name.ToString() ,  "Simple" );				
				ini_config.setValue( "Setting", "Options", StringLib.deParseOption(options) );
			}
			
			if( !Directory.Exists( dir_clock ) ){
				Directory.CreateDirectory( dir_clock );
				
				//Create default lock
				ClockRes.Simple.Save( Path.Combine(dir_clock,"Simple.png"), ImageFormat.Png );
				FileLib.writeFile( Path.Combine(dir_clock,"Simple.ini"), "White,White,Red,0" );
			}
			string[] clocks = FileLib.getFileList( dir_clock, "*.png", true, FileLib.SearchOption.FileOnly );
			foreach( string clock in clocks ){
				string name    	= Path.GetFileNameWithoutExtension( clock );
				string config  	= Path.ChangeExtension( clock, "ini" );				
				config			= File.Exists(config) ? FileLib.readFile(config) : "White,White,Red,0";
				
				if( !ini_config.isKeyExist( "Clocks", name ) )
					ini_config.setValue( "Clocks", name, config );
			}
		}
		
		#region Functions
		public override object InitGadget(){
			if( control == null ){
				control = new ClockPanel(this);
				UpdateOptions(false);
			}
			return control;
		}		
						
		public override void ViewOptions(){
			if( sidebarGadgetOption == null ) sidebarGadgetOption = new Options(this);
			sidebarGadgetOption.Show();
		}
		#endregion
	}
}
